package com.vrv.utils;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.vrv.entity.AdminInfo;

/**
 * Created by Administrator on 2015/3/25.
 */
public class AdminUtil {

    /**
     * 日志
     */
    private static final Logger log = Logger.getLogger(AdminUtil.class);

    public static void setAdmin(HttpServletRequest request, AdminInfo pEmployee) {
        request.getSession().setMaxInactiveInterval(getTimeOut());
        request.getSession().setAttribute("LOGINUSER", pEmployee);
    }

    public static Object getAdmin(HttpServletRequest request) {
        request.getSession().setMaxInactiveInterval(getTimeOut());
        return request.getSession().getAttribute("userInfo");
    }

    public static int getType(HttpServletRequest request) {
        request.getSession().setMaxInactiveInterval(getTimeOut());
        int type = (int) request.getSession().getAttribute("type");
        return type;
    }

    public static int getTimeOut() {
        int timeout = 0;
        String session_timeout = SystemConfig.readValue("session_timeout");
        if (StringUtils.isNotBlank(session_timeout)) {
            timeout = Integer.parseInt(session_timeout);
        }

        if (log.isDebugEnabled()) {
            log.debug("timeout:" + timeout);
        }
        return timeout;
    }

}
